package system;

import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import cards.Card;
import cards.CardType;

//Using Mockito
public class TestTurnstile {
	
	Card mockCard;
	CentralSystem mockSystem;
	Turnstile turn;
	
	@Before
	public void init() {
		mockCard = mock(Card.class);
		mockSystem = mock(CentralSystem.class);
		turn = new Turnstile();
	}
	
	@Test
	public void testCheckOnCardCalledOnce() {
		turn.check(mockCard);
		verify(mockCard, times(1)).check();
	}
	
	@Test
	public void testTurnCheckReturnFalseWhenCardCheckReturnFalse() {
		when(mockCard.check()).thenReturn(false);
		
		boolean expectedStatus = false;
		boolean actualStatus = turn.check(mockCard);
		assertEquals(expectedStatus, actualStatus);
		
	}
	
	@Test
	public void testTurnCheckReturntrueWhenCardCheckReturnTrue() {
		when(mockCard.check()).thenReturn(true);
		
		boolean expectedStatus = true;
		boolean actualStatus = turn.check(mockCard);
		assertEquals(expectedStatus, actualStatus);
		
	}
	
	@Test
	public void testSendStatCalledOnce() {
		turn = new Turnstile(mockSystem);
		when(mockCard.getType()).thenReturn(CardType.COMMON_10);
		turn.check(mockCard);
		verify(mockSystem, times(1)).sendStat(anyString(), anyBoolean());
	}
	
	@Test
	public void testSendStatSendFalseWhenCheckReturnFalse() {
		turn = new Turnstile(mockSystem);
		when(mockCard.getType()).thenReturn(CardType.COMMON_10);
		when(mockCard.check()).thenReturn(false);
		turn.check(mockCard);
		verify(mockSystem).sendStat(anyString(), eq(false));
	}
	
	@Test
	public void testSendStatSendTrueWhenCheckReturnTrue() {
		turn = new Turnstile(mockSystem);
		when(mockCard.getType()).thenReturn(CardType.COMMON_5);
		when(mockCard.check()).thenReturn(true);
		turn.check(mockCard);
		verify(mockSystem).sendStat(anyString(), eq(true));
	}
	
	@Test
	public void testSendStatSendCorrectCardType() {
		turn = new Turnstile(mockSystem);
		when(mockCard.getType()).thenReturn(CardType.STUDENT_10);
		turn.check(mockCard);
		verify(mockSystem).sendStat(eq(CardType.STUDENT_10.name()), anyBoolean());
	}
}
